﻿
@{
    ViewData["Title"] = "产品管理|恩腾五金ERP";
    Layout = "~/Views/Shared/_layout2.cshtml";
}


@using ETWJ.DTO
@model List<ProductDTO>


<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 产品管理</strong></div>
        <div class="padding border-bottom">
            <ul class="search">
                <li>
                    <button type="button" class="button border-green" id="checkall"><span class="icon-check"></span> 全选</button>
                    <button type="button" id="addEmployee" class="button border-blue"><span class="icon-road"></span> 添加</button>
                    <button type="button" id="editEmployee" class="button border-blue"><span class="icon-edit"></span> 修改</button>
                    <button type="button" id="deletedEmployee" class="button border-red"><span class="icon-trash-o"></span> 批量删除</button>

                </li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th width="120">ID</th>
                <th>产品编码</th>
                <th>产品名称</th>
                <th>产品价格</th>
                <th>产品类型</th>
                <th>添加时间</th>
            </tr>

            @foreach (var product in Model)
            {
                <tr>
                    <td>
                        <input type="checkbox" name="id[]" value="@product.Id" />
                        @product.Id
                    </td>
                    <td>@product.ProductCode</td>
                    <td>@product.Name</td>
                    <td>￥：@product.Price</td>
                    <td>
                        @if (product.Type == 1)
                        {
                            <text>金属类型</text>
                        }
                        else if (product.Type == 2)
                        {
                            <text>塑料类型</text>
                        }
                        else
                        {
                            <text>其他类型</text>
                        }

                    </td>
                    <td>@product.AddTime</td>
                </tr>
            }

            <tr>
                <td colspan="11">
                    <div class="pagelist">
                        <a href="/Product/List?PageIndex=1">首页</a>
                        <a href="/Product/List?PageIndex=@(Convert.ToInt32(@ViewBag.CurrentPageIndex-1)>0?Convert.ToInt32(@ViewBag.CurrentPageIndex-1):1)">上一页</a>
                        @for (var i = 1; i <= ViewBag.PageCount; i++)
                        {
                            @*<span class="current"></span>*@
                            if (i == ViewBag.CurrentPageIndex)
                            {
                                <a href="/Product/List?PageIndex=@i" style="background-color:#09F; color:white;">@i</a>
                            }
                            else
                            {
                                <a href="/Product/List?PageIndex=@i">@i</a>
                            }

                        }
                        <a href="/Product/List?PageIndex=@((Convert.ToInt32(ViewBag.CurrentPageIndex)+1)>ViewBag.PageCount?ViewBag.PageCount:(Convert.ToInt32(ViewBag.CurrentPageIndex)+1))">下一页</a>
                        <a href="/Product/List?PageIndex=@ViewBag.PageCount">尾页</a>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">

function del(id){
	if(confirm("您确定要删除吗?")){

	}
}

$("#checkall").click(function(){
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

function DelSelect(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {
		Checkbox=true;
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

</script>


<script>

    $(function () {

        // 点击新增用户按钮
        $("#addEmployee").click(function () {
            window.location.href = "/Product/Add";
        });

        // 修改用户
        $("#editEmployee").click(function () {
            var ids=new Array();　//创建一个数组  ;
            $("input[name='id[]']").each(function () {
                if (this.checked) {
                    ids.push($(this).val());

                }
            });
            if (ids.length <= 0) {
                alert("请选中一个再进行修改操作！");
                return;
            }
            if (ids.length >= 2) {
                alert("只能选中一个进行修改操作！");
                return;
            }

            //alert(ids)
            window.location.href = "/Product/Edit?id=" + ids;
        });

        // 删除/批量删除
        $("#deletedEmployee").click(function () {
            var ids = new Array();　//创建一个数组  ;
            $("input[name='id[]']").each(function () {
                if (this.checked) {
                    ids.push($(this).val());

                }
            });
            if (ids.length <= 0) {
                alert("请选中一个再进行删除操作！");
                return;
            }
            if (confirm("您确定要删除吗?")) {
                //alert(ids)
                window.location.href = "/Product/BatchDeleted?ids=" + ids;
            }

        });
    })
</script>



